<?php

class Dosen extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('model_user');
        $this->load->model('model_grup');
        $this->load->model('model_posting');
        $this->load->model('model_pm');
        $this->load->model('model_comment');
        if ($this->model_user->auth() == 0 || $this->model_user->auth() !== 1) {
            redirect('login/index');
        } else {
            if ($this->session->userdata['level'] == 'mahasiswa') {
                redirect('mahasiswa');
            }
        }
    }

    function index() {
        $data['nama'] = $this->session->userdata['nama'];
        $data['main_content'] = 'welcome';
        $this->load->view('includes/template', $data);
    }
    
    function createGroup(){
        $this->load->view('groups/createGroup');
    }
    
    function submitGroup(){
        if($this->model_grup->submitGroup()){
            echo "<script type='text/javascript'>parent.$.fancybox.close();</script>";
        }else{
            echo "<script type='text/javascript'>alert('gagal gan');</script>";
        }
    }
    
    function groupList(){
        $data['rows'] = $this->model_grup->getAll();
        $data['main_content'] = 'groups/listGroup';
        $this->load->view('includes/template',$data);
    }
    
    function groupId($id){
        $data['row'] = $this->model_grup->getGroupById($id);
        $data['postings'] = $this->model_posting->show_posting($id);
        $data['members'] = $this->model_grup->getMembers($id);
        $data['main_content'] = 'groups/idGroup';
        $this->load->view('includes/template', $data);
    }
    
    function compose_launch($id){
        $data['id'] = $id;
        $this->load->view('groups/compose', $data);
    }
    
    function compose_submit(){
        if($this->model_posting->insert_posting()){
            echo "<script type='text/javascript'>window.top.window.posted();</script>";
        }else{
            echo "<script type='text/javascript'>alert('gatot');</script>";
        }
    }
    
    function refresh_posting($id){
        $data['postings'] = $this->model_posting->show_posting($id);
        $this->load->view('groups/showPostings', $data);
    }
    
    function add_member($id){
        $data['id'] = $id;
        $this->load->view('groups/add_member', $data);
    }
    
    function cek_member(){
        $q = $this->input->post('q');
        $id = $this->input->post('id_group');
        $data['id_group'] = $this->input->post('id_group');
        $data['rows'] = $this->model_user->cek_member($q,$id);
        $this->load->view('groups/search_member', $data);
    }
    
    
    
    function adding(){
        $this->model_grup->adding();
    }
 
    function launch_pm(){        
        $this->load->view('pm/send_pm');
    }
    
   function compose_pm(){
        if($this->model_pm->sendpm()){
            echo "<script type='text/javascript'>window.top.window.posted();</script>";
        }else{
            echo "<script type='text/javascript'>alert('gatot');</script>";
        }
    }
    
    function pmList(){
        $data['rows'] = $this->model_pm->getAll();
        $data['main_content'] = 'pm/listPm';
        $this->load->view('includes/template',$data);
    }
    
    function comment(){
        $this->model_comment->insertComment();
    }

}

?>
